﻿using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace UtilLib
{
    public static class FileInfoHelper
    {
        /// <summary>
        /// get file sha1
        /// </summary>
        /// <param name="fileInfo"></param>
        /// <returns></returns>
        public static string GetFileHash(this FileInfo fileInfo)
        {
            try
            {
                using (var fs = new FileStream(fileInfo.FullName, FileMode.Open))
                using (var bs = new BufferedStream(fs))
                {
                    using (var sha1 = new SHA1Managed())
                    {
                        var hash = sha1.ComputeHash(bs);
                        var formatted = new StringBuilder(2 * hash.Length);
                        foreach (var b in hash)
                        {
                            formatted.AppendFormat("{0:X2}", b);
                        }

                        return formatted.ToString();
                    }
                }
            }
            catch (Exception)
            {
                return string.Empty;
            }
        }

        public static void FileCopy(this FileInfo sourceFile, string destFile, bool bCover)
        {
            
        }
    }
}
